package com.yupi.yuaiagent.demo.invoke;

import jakarta.annotation.Resource;
import org.springframework.ai.chat.messages.AssistantMessage;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * @className: SpringAiAiInvoke
 * @author: xxy-Rain
 * @date: 2025/10/18 11:29
 * @version: 1.0
 * @description: TODO
 * SPRING AI 框架调用AI
 */
@Component
public class SpringAiAiInvoke implements CommandLineRunner {

    //细节，springboot是先名称再类型。所以要将变量名写为dashscopeChatModel，这样才能准确的访问到
    @Resource
    private ChatModel dashscopeChatModel;


    @Override
    public void run(String... args) throws Exception {
        AssistantMessage assistantMessage = dashscopeChatModel.call(new Prompt("你好，我是Rain"))
                .getResult()
                .getOutput();
        System.out.println(assistantMessage.getText());
    }
}
